package cst.neu.yuejian_31.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.List;

import cst.neu.yuejian_31.R;
import cst.neu.yuejian_31.activity.CourseDetailActivity;
import cst.neu.yuejian_31.bean.CcourseBean;
import cst.neu.yuejian_31.Common.Constant;

/**
 * Created by xxe on 2017/10/18.
 */

public class CcourseAdapter extends RecyclerView.Adapter {
    private Context context;
    private LayoutInflater layoutInflater;
    private List<CcourseBean> list;

    public CcourseAdapter(Context context){
        this.context=context;
        layoutInflater=LayoutInflater.from(context);
    }
    public void setList(List<CcourseBean> list){
        this.list=list;
        notifyDataSetChanged();
    }
    public class ViewHolder extends RecyclerView.ViewHolder{
        private TextView ccName,ccMoney,ccTeacher;
        private ImageView ccPic;
        public ViewHolder(View itemView) {
            super(itemView);
            ccPic= (ImageView) itemView.findViewById(R.id.imageView_cclass);
            ccName= (TextView) itemView.findViewById(R.id.textView_cclass_name);
            ccTeacher= (TextView) itemView.findViewById(R.id.textView_teacher);
            ccMoney= (TextView) itemView.findViewById(R.id.textView_money);

        }
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v=layoutInflater.inflate(R.layout.item_ccourse,parent,false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final CcourseBean ccourseBean=list.get(position);
        if(ccourseBean==null)
            return;
        ViewHolder viewHolder= (ViewHolder) holder;
        viewHolder.ccMoney.setText(ccourseBean.getClubclass_money());
        viewHolder.ccName.setText(ccourseBean.getClubclass_name());
        viewHolder.ccTeacher.setText(ccourseBean.getClassteacher_name());
        Picasso.with(context).load(Constant.CLASS_URL+ccourseBean.getClubclass_pic()).placeholder(R.drawable.julebu).into(viewHolder.ccPic);

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, CourseDetailActivity.class);
                intent.putExtra("course_id",ccourseBean.getClubclass_id());
                intent.putExtra("course_name",ccourseBean.getClubclass_name());
                intent.putExtra("course_intro",ccourseBean.getClubclass_introduce());
                intent.putExtra("course_pic",ccourseBean.getClubclass_pic());
                intent.putExtra("course_money",ccourseBean.getClubclass_money());
                intent.putExtra("course_Btime",ccourseBean.getClubclass_starttime());
                intent.putExtra("course_Etime",ccourseBean.getClubclass_endtime());
                intent.putExtra("course_teacher",ccourseBean.getClassteacher_name());
                intent.putExtra("course_address",ccourseBean.getClubclass_adress());
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        if (list==null)return 0;
        else
            return list.size();
    }
}
